package com.junmeng.libfloating.tab

import android.app.Activity
import android.view.View
import android.widget.Toast
import androidx.fragment.app.FragmentActivity
import com.junmeng.lib.ui.topview.core.WindowTopViewManager
import com.junmeng.libfloating.util.FragmentUtil

/**
 * 当前显示的Fragment
 */
class Menu0() : TabMenu.Item() {
    private var clickListener = View.OnClickListener {

        val activity: Activity? = WindowTopViewManager.getCurrentActivity()
        var current: String = activity?.javaClass?.canonicalName ?: "unknown"
        if (activity is FragmentActivity) {
            val curFrag =
                FragmentUtil.findVisibleFragment(activity, 0f, 0f)
            if (curFrag != null) {
                current = current + ":\n" + curFrag.javaClass.canonicalName
            }
        }
        Toast.makeText(it.context, current, Toast.LENGTH_LONG).show()
    }

    override fun getClickListener(): View.OnClickListener? {
        return clickListener
    }

    override fun getLabel(): String {
        return "当前Fragment"
    }
}